package com.ds.lens.data.controller;

import com.ds.lens.data.common.document.Event;
import com.ds.lens.data.service.LensEventService;
import com.ds.lens.data.vo.BaseOutVO;
import com.ds.lens.data.vo.factory.VOFactory;
import com.ds.lens.data.vo.in.PagedConditionInVO;
import com.ds.lens.data.vo.in.User;
import com.ds.lens.data.vo.in.v2.event.EventInVO;
import com.ds.lens.data.vo.out.v2.event.EventListOutVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Description:
 *
 * @author hill
 * @date 2019-11-12
 */
@Slf4j
@RestController
@Api(value = "Lens Event controller")
@RequestMapping(produces = {"application/json;charset=UTF-8"})
public class LensEventController {

    @Autowired
    LensEventService lensEventService;

    /**
     * Paging for query event
     *
     * @param inVO conditions
     * @return BaseOutVO object
     */
    @ApiOperation(value = "Paging for query event")
    @PostMapping(value = "/lens/events")
    public BaseOutVO getLensEvents(@RequestBody @Valid PagedConditionInVO<EventInVO> inVO,
                                   @RequestAttribute(value = "user") User user) {
        EventListOutVO eventList = lensEventService.getEventList(inVO, user);
        return VOFactory.getSuccessBaseOutVO(eventList);
    }

    /**
     * Paging for query event
     * @param uid
     * @return BaseOutVO object
     */
    @ApiOperation(value = " query event by ID")
    @GetMapping(value = "/lens/getLensEventById")
    public BaseOutVO getLensEventById(@RequestParam("uid") String uid,
                                      @RequestAttribute(value = "user") User user) {
        Event event = lensEventService.getLensEventById(uid, user);
        return VOFactory.getSuccessBaseOutVO(event);
    }

}
